package com.ptu.service.impl;

import com.ptu.entity.Dept;
import com.ptu.mapper.DeptMapper;
import com.ptu.service.DeptService;
import com.ptu.util.DBUtil;

import java.util.List;


public class DeptServiceImpl implements DeptService {

    @Override
    public List<Dept> findAll() {
        DeptMapper mapper = DBUtil.getSqlSession().getMapper(DeptMapper.class);
        List<Dept> depts = mapper.selectAll();
        DBUtil.closeAll();
        return depts;
    }
    @Override
    public int addDept(Dept dep){
        DeptMapper mapper = DBUtil.getSqlSession().getMapper(DeptMapper.class);
        int add = mapper.insertDept(dep);
        DBUtil.closeAll();
        return add;
    }

    //修改部门操作
    @Override
    public int changeDept(Dept dep){
        DeptMapper mapper = DBUtil.getSqlSession().getMapper(DeptMapper.class);
        int update = mapper.updateDept(dep);
        DBUtil.closeAll();
        return update;
    }

    //查询部门操作
    @Override
    public Dept findOneDept(Integer deptno){
        DeptMapper mapper = DBUtil.getSqlSession().getMapper(DeptMapper.class);
        List<Dept> dt = mapper.selectOneDept(deptno);
        DBUtil.closeAll();
        return dt.get(0);
    }

    //删除部门信息
    @Override
    public int removeDept(Dept dept){
        DeptMapper mapper = DBUtil.getSqlSession().getMapper(DeptMapper.class);
        int del = mapper.delDept(dept);
        DBUtil.closeAll();
        return del;
    }

}
